package org.txazo.blog.web.action;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.txazo.blog.web.action.base.BaseAction;

/**
 * BlogAction
 * 
 * @author Tu XiaoZhou
 * @since 2013-08-28
 * 
 */
@Controller
@Scope("session")
@Namespace("/blog")
public class BlogAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	private String title;
	private String content;

	/**
	 * 保存
	 */
	@Action(value = "save", results = { @Result(name = SUCCESS, location = "/register/register.jsp") })
	public String save() {
		try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
				new FileOutputStream("D:/out.txt")))) {
			bw.write(content);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	/**
	 * 编辑
	 */
	@Action(value = "edit", results = { @Result(name = SUCCESS, location = "/blog/blog-edit.jsp") })
	public String edit() {
		return SUCCESS;
	}

	/**
	 * 删除
	 */
	@Action(value = "remove", results = { @Result(name = SUCCESS, location = "/register/register-mail-confirm.jsp") })
	public String remove() {
		return SUCCESS;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

}
